package com.scse.bms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scse.bms.domain.RepositoryVO;
import com.scse.bms.entity.RepositoryDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @Title: RepositoryMapper
 * @Author: 吴赠禹
 * @Date: 2021/3/4 13:02
 * @Version: 1.0
 * @Description: 书库dao
 */


@Mapper
@Repository
public interface RepositoryMapper extends BaseMapper<RepositoryDO> {

    /**
     * 批量插入仓库
     * @return
     */
    int insertBatch(List<RepositoryVO> list);


    /**
     * 分页查询书库列表
     */
    @Select("select id, title, author, press, press_time, description," +
            "src,img,size,is_free,upload_time,ISBN from t_repository")
    IPage<RepositoryDO> selectAll(Page<?> page);


    /**
     * 通过审核，加入图书列表
     */
    @Insert("insert into t_book(title, author, press, press_time, description, src, img, size, upload_time, ISBN)" +
            "select title, author, press, press_time, description, src, img, size, upload_time, ISBN from t_repository where id = #{id}")
    int insertIntoBook(Integer id);


    /**
     * 批量删除
     */
    int deleteBatch(List<Integer> list);


    /**
     * 通过审核的图书批量加入书架（book表，未上架）
     * @param list
     * @return
     */
    int addToBookrackBatch(List<RepositoryDO> list);


}
